package com.itheima.controller;

import com.itheima.advice.RecordLogAnno;
import com.itheima.pojo.Clazz;
import com.itheima.pojo.ClazzQueryParam;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.service.ClazzService;
import com.sun.xml.bind.v2.TODO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RestController
@RequestMapping("/clazzs")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;

    @GetMapping
    public Result clazzPage(ClazzQueryParam clazzQueryParam) {
        PageResult<Clazz> classPageResult = clazzService.clazzPage(clazzQueryParam);
        log.info("班级信息分页查询");
        return Result.success(classPageResult);
    }

    //数据回显
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        Clazz clazz = clazzService.getClazzById(id);
        log.info("班级信息数据回显");
        return Result.success(clazz);
    }

    @RecordLogAnno
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id) {
        clazzService.deleteById(id);
        log.info("班级信息删除");
        return Result.success();
    }

    @PostMapping
    @RecordLogAnno
    public Result save(@RequestBody Clazz clazz) {
        clazzService.save(clazz);
        log.info("添加班级信息");
        return Result.success();
    }

    @PutMapping
    @RecordLogAnno
    public Result updateClazz(@RequestBody Clazz clazz){
        clazzService.updateClazz(clazz);
        log.info("修改班级信息");
        return Result.success();
    }

    @GetMapping("/list")
    public Result getAllClazz(){
        List<Clazz> clazzList = clazzService.list();
        log.info("查询全部班级信息");
        return Result.success(clazzList);
    }

}
